/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2019-07-20 14:16:27
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-18 09:44:52
 */
import React, { Component } from 'react';
import { observer, inject } from 'mobx-react';
import { Row, Col } from 'antd';
import { toJS } from 'mobx';
import { hashHistory } from 'react-router';
import { WeaReportCard, WeaLocaleProvider } from 'ecCom';

const { getLabel } = WeaLocaleProvider;

@inject('centerStore')
@observer
class OdocCenterLibraryComp extends Component {
  componentDidMount() {
    const { centerStore } = this.props;
    centerStore.buildLibrarys();
  }

  render() {
    return (
      <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@cd3p8h`} id="rowLibrarys" className="wea-odoc-center-right-row">
        <WeaReportCard ecId={`${this && this.props && this.props.ecId || ''}_WeaReportCard@xdujwe`}
          title={<span><span className="icon-coms-yellow-big"><i className="icon-coms-official" /></span>{getLabel('383001', '公文库')}</span>}
          onMoreClick={this.jumpToLibrary}
        >
          {this.renderLibrarys()}
        </WeaReportCard>
      </Row>

    );
  }

  renderLibrarys() {
    const { centerStore } = this.props;
    let librarys = toJS(centerStore.librarys);
    let rows = [];
    if (librarys.length > 0) {
      librarys.map((data, index) => {
        rows.push(
          <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@mxxkoj@${index}`} span={12}>
            <div className="right_c1">
              <div className="right_c1_r">
                <div className="right_c1_r-top">
                  <p dangerouslySetInnerHTML={{ __html: data.showlink }} />
                </div>
                <div className="right_c1_r-bottom">
                  {data.createdatetime}&nbsp;&nbsp;&nbsp;&nbsp;
                </div >
              </div>
            </div>
          </Col>,
        );
      });
    }
    return (rows);
  }

  jumpToLibrary = () => {
    const { centerStore } = this.props;
    const formData = centerStore.searchStore.form.getFormParams();
    let params = {
      ...formData,
    };

    let path = {
      pathname: '/main/offical/odocLibraryNew',
      query: params,
    };

    hashHistory.push(path);
  }
}

export default OdocCenterLibraryComp;
